package com.mall.controller;

import com.mall.pageResult.PageResult;
import com.mall.pojo.SmsHomeNewProduct;
import com.mall.pojo.SmsHomeRecommendProduct;
import com.mall.service.HomeRecommendProductService;
import com.mall.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/recommendProduct")
public class HomeRecommendProductController {

    @Autowired
    private HomeRecommendProductService homeRecommendProductService;

    /**
     * 分页查询首页人气商品
     * @param pageNum
     * @param pageSize
     * @param productName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult<SmsHomeRecommendProduct>> list(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                            @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                            @RequestParam(required = false) String productName,
                                                            @RequestParam(required = false) Integer recommendStatus){
        PageResult<SmsHomeRecommendProduct> result = homeRecommendProductService.list(pageNum,pageSize,productName,recommendStatus);
        return Result.success(result,"操作成功");
    }

    /**
     * 批量修改首页人气商品状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public Result<Integer> updateRecommendStatus(Long[] ids, Integer recommendStatus) {
        Integer count = homeRecommendProductService.updateRecommendStatus(ids, recommendStatus);
        return Result.success(count, "操作成功");
    }

    /**
     * 添加首页人气商品
     * @param homeRecommendProductList
     * @return
     */
    @PostMapping("/create")
    public Result<Integer> create(@RequestBody List<SmsHomeRecommendProduct> homeRecommendProductList) {
        Integer count = homeRecommendProductService.create(homeRecommendProductList);
        return Result.success(count, "操作成功");
    }

    /**
     * 修改首页人气商品排序
     * @param id
     * @param sort
     * @param hid
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public Result<Integer> updateSort(@PathVariable Integer id, @RequestParam Integer sort, @RequestParam(value = "id") Integer hid) {
        Integer count = homeRecommendProductService.updateSort(id,sort);
        return Result.success(count,"操作成功");
    }

    /**
     * 批量删除首页人气商品
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public Result<Integer> delete(Long[] ids){
        Integer count = homeRecommendProductService.delete(ids);
        return Result.success(count, "操作成功");
    }
}
